/**
 *  Copyright (C) 2010:
 *                 Buzzanca Marco <marco.bzn@gmail.com>
 *         Monaco Davide Giuseppe <black.ralkass@gmail.com>
 *              Petralia Veronica <veronicapetralia@gmail.com>
 *
 * This file is part of DS2011BMP
 *
 * DS2011BMP is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * DS2011BMP is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

/**
 * @file address.h
 * @author Veronica Petralia
 * @author Marco Buzzanca
 *
 * This header file contains Address class declaration.
 */

#ifndef _ADDRESS_H_
#define _ADDRESS_H_

#include <string>
#include <boost/asio.hpp>
#include <boost/cstdint.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/serialization/vector.hpp>

/**
 * @brief Port type according to boost library specifications.
 */
typedef boost::uint16_t Port;

/**
 * @brief The Address class specifies the pair <IP address-port> of an
 * entity in the distributed system.
 */
class Address
{
	private:

    // enables boost serialization access
    friend class boost::serialization::access;

    /**
     * @brief Serialization member function.
     *
     * boost::serialization needs it.
     */
    template <class Archive>
    void serialize(Archive& ar, const unsigned int version)
    {
      ar & _port;
      ar & _IP;
    }

    /**
     * Current Address Port.
     */
		boost::uint16_t _port;

    /**
     * Current Address IP address.
     */
		std::string _IP;

	public:
    /**
     * @brief Default constructor
     */
		Address(void);

    /**
     * @brief Constructor to specific port
     * @param val   the specific port.
     */
		Address(boost::uint16_t val);

    /**
     * @brief Constructor with IP address provided.
     * @param ip    the provided ip address.
     */
		Address(const std::string& ip);

    /**
     * @brief Constructor with IP address ond port provided.
     * @param ip    the provided ip address.
     * @param p     the provided port.
     */
		Address(const std::string& ip, boost::uint16_t p);

    /**
     * @brief Destructor
     */
		~Address(void);

    /**
     * @brief This method returns value of port
     * @return current port.
     */
		boost::uint16_t getPort() const;

    /**
     * @brief Set current port to the provided value.
     * @param val   provided port.
     */
		void setPort(boost::uint16_t val);

    /**
     * @brief This method returns value of IP
     * @return current IP address.
     */
		const std::string getIP() const;

    /**
     * @brief Set current IP address to the provided value.
     * @param val   provided IP address.
     */
		void setIP(const std::string& val);
};

#endif
